package com.united.ucts.generator;

import com.united.frame.generator.CodeGenerateUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 代码生成器
 *
 * @author hudan
 * @version 1.0
 * @filename CodeGenerateUtils.java
 * @copyright <a href="www.united.cn">www.united.cn</a>
 * @date 2019-10-21
 */
public class TestCodeGenerator {

    private static final String author = "Hudan";
    private static final String javaFilePath = "/Volumes/Data/Project/WorkPro/unitedft/UnitedPro_KF/x-ucts/ucts-modules/ucts-admin/src/main/java/";
    private static final String testFilePath = "/Volumes/Data/Project/WorkPro/unitedft/UnitedPro_KF/x-ucts/ucts-modules/ucts-admin/src/test/java/";
    private static final String resourceFilePath = "/Volumes/Data/Project/WorkPro/unitedft/UnitedPro_KF/x-ucts/ucts-modules/ucts-admin/src/main/resources/";
    private static final String packageName = "com.united.base";
    private static final String moduleName = "system";

    private static final String driver = "com.mysql.cj.jdbc.Driver";
    private static final String url = "jdbc:mysql://localhost:3306/united-ucts?useUnicode=true&characterEncoding=utf-8";
    private static final String user = "root";
    private static final String password = "root";

    public static void testGenerate() {
        List<String> tables = new ArrayList<>();
        tables.add("sys_menu, Menu, 系统菜单基本信息表");
        tables.add("sys_org, Org, 系统机构信息表");
        tables.add("sys_permission, Permission, 系统权限信息表");
        tables.add("sys_resource, Resource, 系统资源信息表");
        tables.add("sys_role, Role, 系统角色基本信息表");
        tables.add("sys_user, User, 系统用户基本信息表");

        tables.add("sys_resource_category, ResourceCategory, 系统资源类型信息表");
        tables.add("sys_role_menu, RoleMenu, 角色菜单关联信息表");
        tables.add("sys_role_permission, RolePermission, 角色权限关联信息表");
        tables.add("sys_role_resource, RoleResource, 角色资源关联信息表");
        tables.add("sys_user_role, UserRole, 用户角色关联信息表");

        for (String table : tables) {
            String[] tableArr = table.split(", ");
            String tableName = StringUtils.trim(tableArr[0]);
            String className = StringUtils.trim(tableArr[1]);
            String tableDesc = StringUtils.trim(tableArr[2]);
            CodeGenerateUtils codeGenerateUtils = new CodeGenerateUtils(javaFilePath, resourceFilePath, testFilePath, packageName, moduleName, tableName, tableDesc, className, author,
                    driver, url, user, password);
            codeGenerateUtils.generate();
        }
        System.out.println("代码生成完成!");
    }
}